package com.example.sample.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.example.app.BaseActivity;
import com.example.sample.R;
import com.example.sample.logic.MyPagerAdapter;

import androidx.viewpager.widget.ViewPager;

public class ViewPagerActivity extends BaseActivity {

	public final static String TAG = "ViewPagerActivity";
	
	ViewPager mViewPager;
	
	MyPagerAdapter mAdapter;
	
	Button mBtn1;
	Button mBtn2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_viewpager);

        Log.i(TAG, "onCreate");
		
		mBtn1 = (Button)findViewById(R.id.button1);
		mBtn1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mViewPager.setCurrentItem(0);
			}
		});
		mBtn2 = (Button)findViewById(R.id.button2);
		mBtn2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mViewPager.setCurrentItem(1);
			}
		});
		mViewPager = (ViewPager)findViewById(R.id.pager);
		mAdapter = new MyPagerAdapter(this);
		mViewPager.setAdapter(mAdapter);
		mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int position) {
				Log.i(TAG, "onPageSelected"+position);
				switch (position) {
				case 0:					
					break;
				case 1:					
					break;
				default:
					break;
				}
			}
			
			@Override
			public void onPageScrolled(int position, float positionOffset,
					int positionOffsetPixels) {
				Log.i(TAG, "onPageScrolled"+position+ "/"+ positionOffset + "/" +  positionOffsetPixels);
			}
			
			@Override
			public void onPageScrollStateChanged(int state) {
				Log.i(TAG, "onPageScrollStateChanged" + state);
			}
		});
	}
}
